//
//  ClassPageViewController.m
//  AmountBody
//
//  Created by smm on 2017/12/12.
//  Copyright © 2017年 RCMTM. All rights reserved.
//

#import "ClassPageViewController.h"
#import "ClassViewController.h"
#import "ClassModel.h"
#import "SearchViewController.h"
#import "SearchClassShowView.h"
#define MenuVuewH  64
@interface ClassPageViewController ()
@property (strong, nonatomic) SearchClassShowView * s_classView;
@end

@implementation ClassPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadUI];
    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [SearchClassShowView blockForBackButton:^{
        [self.navigationController popViewControllerAnimated:YES];
    }];
    [SearchClassShowView blockForSearchButton:^(NSString *searchStr,BOOL isReturn) {
        SearchViewController * tmpVC = [MAIN_STORYBOARD instantiateViewControllerWithIdentifier:@"SearchViewController"];
        tmpVC.hidesBottomBarWhenPushed  = YES;
        tmpVC.keyWord = searchStr;
        [self.navigationController pushViewController:tmpVC animated:YES];
    }];
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark -  UI布局
-(void)loadUI
{
    NSArray * Arr = [NSArray arrayWithObjects:@"衣服",@"男士衬衫",@"男士西装",@"西裤",@"扣子",@"布料",@"风衣",@"毛呢", nil];
    NSMutableArray * classArr = [[NSMutableArray alloc]init];
    for (int i=0; i<Arr.count; i++) {
        ClassModel * model = [[ClassModel alloc]init];
        model.name = [Arr objectAtIndex:i];
        model.class_id = [NSString stringWithFormat:@"%d",i];
        [classArr addObject:model];
    }
    self.selectIndex = _index;
    self.itemMargin = 0;
    CGFloat searchViewH = 64;
    [_s_classView removeFromSuperview];
    _s_classView = [[SearchClassShowView alloc]init];
    [self.view addSubview:_s_classView];
    [_s_classView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view);
        make.height.equalTo(@(searchViewH));
    }];
    [_s_classView loadSearchViewWithClassArray:classArr andHasBack:YES andFirstChoose:@"-1"];
    self.menuView.layoutMode = WMMenuViewLayoutModeLeft;
    
    CGFloat imageW = 19;
    CGFloat imageH = 18;
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 64, 60, MenuVuewH)];
    view.backgroundColor = RGBColorAlpha(44, 44, 44, 1);
    view.layer.shadowColor = RGBColorAlpha(84, 84, 84, 1).CGColor;//shadowColor阴影颜色
    view.layer.shadowOffset = CGSizeMake(-2,2);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
    view.layer.shadowOpacity = 0.8;//阴影透明度，默认0
    view.layer.shadowRadius = 1;//阴影半径，默认3
    UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake((60-imageW)/2.0, (MenuVuewH-imageH)/2.0, imageW, imageH)];
    image.image = [UIImage imageNamed:@"@2Rectangle"];
    [view addSubview:image];
    [self.view addSubview:view];
}
- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    NSArray * classArr = [NSArray arrayWithObjects:@"衣服",@"男士衬衫",@"男士西装",@"西裤",@"扣子",@"布料",@"风衣",@"毛呢", nil];
    return classArr.count;
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    NSArray * classArr = [NSArray arrayWithObjects:@"衣服",@"男士衬衫",@"男士西装",@"西裤",@"扣子",@"布料",@"风衣",@"毛呢", nil];
    return [classArr objectAtIndex:index];
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    NSArray * classArr = [NSArray arrayWithObjects:@"衣服",@"男士衬衫",@"男士西装",@"西裤",@"扣子",@"布料",@"风衣",@"毛呢", nil];
    ClassViewController *classVC =  [[ClassViewController alloc] init];
    classVC.class_id = [NSString stringWithFormat:@"%@",[classArr objectAtIndex:index]];
    return classVC;
}

- (CGFloat)menuView:(WMMenuView *)menu widthForItemAtIndex:(NSInteger)index {
    CGFloat width = [super menuView:menu widthForItemAtIndex:index];
    NSArray * classArr = [NSArray arrayWithObjects:@"衣服",@"男士衬衫",@"男士西装",@"西裤",@"扣子",@"布料",@"风衣",@"毛呢", nil];
    UILabel * label = [[UILabel alloc]init];
    label.text = [classArr objectAtIndex:index];
    [label sizeToFit];
    width = label.frame.size.width;
    return width+15;
}
- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
   
    CGFloat leftMargin = 59;
    menuView.backgroundColor = RGBColorAlpha(44, 44, 44, 1);
    menuView.contentMargin = 0.0;
    menuView.layer.shadowColor = RGBColorAlpha(84, 84,84, 1).CGColor;//shadowColor阴影颜色
    menuView.layer.shadowOffset = CGSizeMake(-2,2);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
    menuView.layer.shadowOpacity = 0.8;//阴影透明度，默认0
    menuView.layer.shadowRadius = 1;//阴影半径，默认3
    return CGRectMake(leftMargin, 64, self.view.frame.size.width - leftMargin+2, MenuVuewH);
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView {
   
    CGFloat originY = MenuVuewH;
    return CGRectMake(0, originY, self.view.frame.size.width, self.view.frame.size.height - originY);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
